﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

namespace CoreWeb.Utility.Filter
{
    public class CustomExpeptionFilterAttribute:ExceptionFilterAttribute
    {
        /// <summary>
        /// 当异常发生时
        /// </summary>
        /// <param name="context"></param>
        public override void OnException(ExceptionContext context)
        {
            if (!context.ExceptionHandled)//如果错误没有被处理
            {
                Console.WriteLine($"{context.HttpContext.Request.Path}{context.Exception.Message}");
                context.Result = new JsonResult(new { Result = false ,Msg="发生一场，请联系管理员"});

            }
            base.OnException(context);
        }
    }
}
